<!-- 申请售后 --><!-- 申请售后 -->
<template>
	<view class="page">
		<u-navbar :isFixed="true" title="申请售后" :borderBottom="false"></u-navbar>
		<view class="goods">
			<view class="flex_align goods">
				<image class="goodsImg" :src="goods.goods_info.image"></image>
				<view class="content">
					<view class="goodsName clamp2">{{goods.goods_info.title}}</view>
					<view class="goodsName clamp2">{{goods.goods_info.spec_value}}</view>
					<view class="price">￥{{goods.goods_info.money}}/{{goods.goods_info.unit}}</view>
				</view>
			</view>
		</view>
		<view class="wrap">
			<view class="item flex_bet_align">
				<view class="name">售后类型<text>*</text></view>
				<view class="picker" @click="salesType=true">
					<view>{{Typeindex>0?afterType[Typeindex]:'请选择'}} <text class="iconfont icon-xwtubiaoku-03"></text></view>
				</view>
			</view>
			<view class="item flex_bet_align">
				<view class="name">售后原因<text>*</text></view>
				<view class="picker" @click="salesCause=true">
					<view>{{Reasonindex>0?afterReason[Reasonindex]:'请选择'}} <text class="iconfont icon-xwtubiaoku-03"></text></view>
				</view>
			</view>
			<view class="item flex_bet_align" v-if="Typeindex==1||Typeindex==3">
				<view class="name">退款金额</view>
				<view class="price">￥{{goods.after_money}}</view>
			</view>
			<view class="item flex_bet_align" v-if="Typeindex==2||Typeindex==4">
				<view class="name">{{Typeindex==2?'补货':'换货'}}数量<text>*</text></view>
				<view class="price flex_bet_align">
					<input v-model="supply_num"  type="number" class="name" placeholder="请输入数量"/>{{goods.goods_info.unit}}
				</view>
			</view>
			<view class="item flex">
				<view class="name">备注说明</view>
				<u-input class="textarea_content" v-model="after_note" type="textarea" :border="false" placeholder=" 请备注详细内容（50字以内）" placeholderStyle="color:#B9B9B9" maxlength="50" :clearable="false" />
			</view>
			<view class="upload">
				<view class="count">上传凭证<text>（{{images.length}}/6）</text></view>
				<u-upload ref="upload" max-size="12328959" :action="action" width="210" height="210" max-count="6" :file-list="echoimages" @on-remove="removeimg" @on-uploaded="uploaded"></u-upload>
			</view>
		</view>
		<view style="height:135rpx;"></view>
		<view class="foot" @click="submit">提交申请</view>
		<!-- 售后类型 -->
		<u-popup v-model="salesType" mode="bottom" border-radius="33">
			<view class="flex_bet_align popup">
				<view class="close"></view>
				<view class="title">售后原因</view>
				<view class="close" @click="salesType=false">关闭</view>
			</view>
			<view class="list">
				<scroll-view scroll-y="true" style="height:400rpx;">
					<view class="item" v-for="(item,index) in afterType" :key="index" @click="setsalesType(index)">{{item}}</view>
				</scroll-view>
			</view>
		</u-popup>
		<!-- 售后原因 -->
		<u-popup v-model="salesCause" mode="bottom" border-radius="33">
			<view class="flex_bet_align popup">
				<view class="close"></view>
				<view class="title">售后原因</view>
				<view class="close" @click="salesCause=false">关闭</view>
			</view>
			<view class="list">
				<scroll-view scroll-y="true" style="height:400rpx;">
					<view class="item" v-for="(item,index) in afterReason" :key="index" @click="setsalesCause(index)">{{item}}</view>
				</scroll-view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	var _this,shak;
	export default {
		data() {
			return {
				id:0,
				goods:{},
				//售后类型list
				afterType:[],
				Typeindex:0,
				//售后原因list
				afterReason:[],
				Reasonindex:0,
				string:'',
				action:'',
				lists:[],
				//显示售后类型
				salesType:false,
				//显示售后原因
				salesCause:false,
				// 上传内容
				images: [],
				//备注说明
				after_note:"",
				supply_num:"",
			}
		},
		onLoad(options) {
			_this = this
			_this.action = _this.$api.getbase() + 'fileupload'
			_this.id=options.id
			_this.getshopping()
			_this.getdata()
		},
		methods: {
			// 获取数据
			getshopping() {
				_this.$api.get("aftergoods", {order_id:_this.id}).then(data => {
					_this.goods=data
				});
			},
			// 获取数据
			getdata() {
				_this.$api.get("getaftertypeservice", {order_id:_this.id}).then(data => {
					_this.afterType = data.afterType
					_this.afterReason = data.afterReason
				});
			},
			
			// 防抖点击
			click_shake(fn){
				if(!_this.shake){
					fn && typeof fn === 'function' && fn()
					_this.shake=true
					setTimeout(function(){
						_this.shake=false
					},500)
				}
			},
			// 删除图片
			removeimg(e) {
				_this.images.splice(e, 1)
			},
			// 上传成功
			uploaded(e) {
				_this.images = []
				e.forEach((item,index) => {
					if(item.response){
						if(item.response.code==1){
							_this.images.push(item.response.data.url)
							
						}else{
							_this.$refs['upload'].remove(index)
						}
					}
				})
			},
			// 设置类型
			setsalesType(index){
				_this.Typeindex=index
				_this.salesType=false
				_this.supply_num=""
			},
			//设置原因
			setsalesCause(index){
				_this.Reasonindex=index
				_this.salesCause=false
			},
			// 提交
			submit() {
				_this.click_shake(function(){
					let data = [{
							value: _this.Typeindex,
							type: 2,
							title: "请选择售后类型"
						}, {
							value: _this.Reasonindex,
							type: 2,
							title: "请选择售后原因"
						}
					]
					if(_this.Typeindex==2||_this.Typeindex==4){
						data.push({value: _this.supply_num,type: 1,title: "请填写数量"})
						data.push({value: [_this.supply_num,_this.goods.number],type: 7,title: "数量不能超过"+_this.goods.number})
					}
					if (_this.$plug.verify(data)) {
						_this.$api.post("aftersalessubmit", {
							order_id: _this.id,
							after_type: _this.Typeindex,
							after_reason: _this.afterReason[_this.Reasonindex],
							after_note: _this.after_note,
							supply_num: _this.supply_num,
							after_images: _this.images.join(','),
							after_order_type:1
						}).then(data => {
							wx.showToast({
								title: "申请提交成功"
							})
							_this.$plug.isonshow(2)
							setTimeout(function() {
								wx.navigateBack({
									delta: 1
								})
							}, 500);
						});
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		background-color: #F8F8F8;
	}
	.goods{
		padding:28rpx 30rpx 38rpx;
		background-color: #FFFFFF;
		margin:13rpx 0 8rpx;
	}
	.wrap{
		background-color: #FFFFFF;
		padding:0 30rpx 42rpx;
		.item{
			line-height: 100rpx;
			border-bottom: 1rpx solid #EEEEEE;
			.name{
				font-size: 28rpx;
				color: #333333;
				text{
					color:#FF0000;
				}
				margin-right: 20rpx;
			}
			.picker{
				font-size: 28rpx;
				color: #1a1a1a;
				text{
					color:#999999;
					font-size: 30rpx;
					margin-left:25rpx;
				}
			}
			.price{
				font-size: 28rpx;
				color: #fb0303;
			}
			input{
				min-width: 366rpx;
				font-size: 28rpx;
			}
		}
		.upload{
			padding-top:45rpx;
			.count{
				font-size: 28rpx;
				color: #333333;
				margin-bottom: 28rpx;
			}
		}
	}
	.foot{
		width: 622rpx;
		height: 70rpx;
		background: linear-gradient(90deg,#38be8c, #06adba 96%);
		border-radius: 36rpx;
		font-size: 26rpx;
		text-align: center;
		line-height: 70rpx;
		color: #ffffff;
		position: fixed;
		bottom: 64rpx;
		left: 64rpx;
		z-index: 50;
	}
	.popup{
		padding:48rpx 30rpx;
		border-bottom: 1rpx solid #EEEEEE;
		.close{
			width: 66rpx;
			height: 48rpx;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Medium;
			font-weight: 500;
			line-height: 48rpx;
			text-align: center;
			color: #c5c5c5;
		}
		.title{
			font-size: 32rpx;
			font-weight: 700;
			text-align: center;
			color: #5d5d5d;
		}
	}
	.list{
		font-size: 30rpx;
		font-weight: 500;
		text-align: center;
		color: #333333;
		padding-top:20rpx;
		padding-bottom: env(safe-area-inset-bottom);
		.item{
			height: 107rpx;
			line-height: 107rpx;
		}
	}
	.goodsImg{
		width: 180rpx;
		height: 180rpx;
		border-radius: 16rpx;
		background-color: #EEEEEE;
		margin-right: 20rpx;
	}
	.content{
		width: 480rpx;
	}
	.goodsName{
		font-size: 28rpx;
		color: #333333;
		line-height: 36rpx;
		height: 72rpx;
	}
	.price{
		font-size: 24rpx;
		font-weight: 500;
		color: #f73f3f;
	}
	.textarea_content{
		flex: 1;
		padding: 20rpx 0;
	}
	.sku{
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: 400;
		color: #999999;
	}
</style>
